var basePath = "";
var now = new Date(); 
var year = now.getYear();  
var month = now.getMonth() + 1;  
var day = new Date(year,month,0);   
var date_last = 1900 + year + '-' + month + '-01' ;
var date = 1900 + year + '-' + month + '-' + day.getDate();  
var date_now = 1900 + year + "-" + month + "-" + now.getDate();
var payline_checkbox = document.getElementsByName('payline_checkbox');
var fundadd_checkbox = document.getElementsByName('fundadd_checkbox');
var dayendstatdetail_checkbox = document.getElementsByName('dayendstatdetail_checkbox');
var pubgroup_conditions = null;//分组用的条件
var myChart;
var type_checked = "bar";
$(document).ready(function() {
	window.addEventListener('resize', function () {//监听窗口变化，延迟组件自适应
		setTimeout(function() {
			if(myChart){
				myChart.resize();
			}
		}, 200);
	});
});
var frame_link = parent.window.document.getElementById("iframe_main");
var href_path = basePath + "jumpView.yachtar?alerttype=1&menu=" ;
function return_main(){
//	window.location.href = href_path + 'qry/CustomReport/CustomReport';
	window.history.back();
}
function payline(){
	window.location.href = href_path + "qry/CustomReport/paylineFrame";
}
function housetype_c(){
	window.location.href = href_path + 'qry/CustomReport/housetypeFrame';
}
function bankbalance_c(){
	window.location.href = href_path + 'qry/CustomReport/bankbalanceFrame';
}
function captureflow_c(){
	window.location.href = href_path + 'qry/CustomReport/captureflowFrame';
}
function timeflow_c(){
	window.location.href = href_path + 'qry/CustomReport/timeflowFrame';
}
function fundtypeflow_c(){
	window.location.href = href_path + 'qry/CustomReport/fundtypeflowFrame';
}
function bankidflow_c(){
	window.location.href = href_path + 'qry/CustomReport/bankidflowFrame';
}
function fundusegive_c(){
	window.location.href = href_path + 'qry/CustomReport/fundusegiveFrame';
}
function fundaddvalue_c(){
	window.location.href = href_path + 'qry/CustomReport/fundaddvalueFrame';
}
function dayendstatdetail_c(){
	window.location.href = href_path + 'qry/CustomReport/dayendstatdetailFrame';
}
function funduseproject_c(){
	window.location.href = href_path + 'qry/CustomReport/funduseprojectFrame';
}
/**
 * 缴存流水分析 图表
 */
var payeddateflag = 1 , payeddate_cycle_flag = 3,amount_flag = 1;
var payline_date;
function paylineFrame(){
	document.onkeydown = (function(event){
		if(event.keyCode == 13){ 
			startcount_payline();
		}
	});
	payline_date = null;
	amount_flag = 1;
	$("#datebox1_pl").datebox('setValue',date_last);
	$("#datebox2_pl").datebox('setValue',date);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1080)'}, function(data){
		$("#paystatus_pl").combobox('loadData',data);
	});
	var yname = '                  缴存流水分析';
	noneContent_bar(yname);
}
var layer = document.createElement("div");
layer.id = "layer";
function startcount_payline(){
	var datas = {};
	var date1 = $("#datebox1_pl").datebox('getValue');
	var date2 = $("#datebox2_pl").datebox('getValue');
	if(date1 == "" || date2 == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		var symbol = $("#symbol_pl").combobox('getValue');
		var paystatus = $("#paystatus_pl").combobox('getValue');
		datas.payeddateflag = payeddateflag;
		datas.date1 = date1;
		datas.date2 = date2;
		datas.payeddate_cycle_flag = payeddate_cycle_flag;
		if(symbol != "all" && symbol !== ""){
			datas.symbol = symbol;
		}
		if(paystatus != ""){
			datas.paystatus = paystatus;
		}
		sendToBfmis_remote(REQUEST_TYPE151, datas, function(data){
			payline_date = data;
			loaddata_pl(data);
		});
	}
}

function payline_ck(){
	if(payline_date != null){
		loaddata_pl(payline_date);
	}
}
function loaddata_pl(data){
	var yname = '                  缴存流水分析';
	var xdates = [],ysumpaymentamount = [];
	var paymentamount_0 = [],paymentamount_1 = [],paymentamount_2 = [];
	for (var i = 0; i < data.length; i++) {
		xdates.push(data[i].g_date);
		if(amount_flag == 1){
			ysumpaymentamount.push(data[i].sumpaymentamount);
			paymentamount_0.push(data[i].paymentamount_0);
			paymentamount_1.push(data[i].paymentamount_1);
			paymentamount_2.push(data[i].paymentamount_2);
		} else if(amount_flag == 2){
			ysumpaymentamount.push((data[i].sumpaymentamount / 10000).toFixed(2));
			paymentamount_0.push((data[i].paymentamount_0 / 10000).toFixed(2));
			paymentamount_1.push((data[i].paymentamount_1 / 10000).toFixed(2));
			paymentamount_2.push((data[i].paymentamount_2 / 10000).toFixed(2));
		} else if(amount_flag == 3){
			ysumpaymentamount.push((data[i].sumpaymentamount / 100000000).toFixed(2));
			paymentamount_0.push((data[i].paymentamount_0 / 100000000).toFixed(2));
			paymentamount_1.push((data[i].paymentamount_1 / 100000000).toFixed(2));
			paymentamount_2.push((data[i].paymentamount_2 / 100000000).toFixed(2));
		}
	}
	if(amount_flag == 1){
		yname += '(单位：元)';
	} else if(amount_flag == 2){
		yname += '(单位：万元)';
	} else if(amount_flag == 3){
		yname += '(单位：亿元)';
	}
	data.yname = yname;
	myChart = echarts.init(document.getElementById('main'));
	// 指定图表的配置项和数据
	var option = {
		tooltip : {
			trigger : 'item'
		},
		legend : {
			data : [ 'Growth', '实缴金额'],
			itemGap : 5
		},
		grid : {
			top : '12%',
			left : '1%',
			right : '10%',
			containLabel : true
		},
		xAxis : [ {
			type : 'category',
			data : xdates
		} ],
		yAxis : [ {
			type : 'value',
			name : data.yname,
			axisLabel : {
				formatter : function(a) {
					a = +a;
					return isFinite(a) ? echarts.format.addCommas(+a )
							: '';
				}
			}
		} ],
		dataZoom : [ {
			show : true,
			start : 54,
			end : 100
		}, {
			type : 'inside',
			start : 94,
			end : 100
		}, {
			show : true,
			yAxisIndex : 0,
			filterMode : 'empty',
			width : 30,
			height : '80%',
			showDataShadow : false,
			left : '93%'
		} ],
		series : [ {
			name : '实缴金额',
			type : 'bar',
			label: {
                normal: {
                    show: true,
                    position: 'top'
                }
            },
			data : ysumpaymentamount
		} ],
	};
	if (payline_checkbox[0].checked) {
		var tmp = {};
		tmp.name = '现金';
		tmp.type = 'bar';
		tmp.label = {normal:{ show: true,  position: 'top' }};
		tmp.data = paymentamount_0;
		option.series.push(tmp);
		option.legend.data.push(tmp.name);
	}
	if (payline_checkbox[1].checked) {
		var tmp = {};
		tmp.name = '支票';
		tmp.type = 'bar';
		tmp.label = {normal:{ show: true,  position: 'top' }};
		tmp.data = paymentamount_1;
		option.series.push(tmp);
		option.legend.data.push(tmp.name);
	}
	if (payline_checkbox[2].checked) {
		var tmp = {};
		tmp.name = '刷卡';
		tmp.type = 'bar';
		tmp.label = {normal:{ show: true,  position: 'top' }};
		tmp.data = paymentamount_2;
		option.series.push(tmp);
		option.legend.data.push(tmp.name);
	}
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}
/**
 * 房屋性质分析 图表
 */
var housetype_ht_flag = 'buildtype',groupcontent_flag = 's_houseid',displaytype_ht_flag = 1;
var curr_parm = null , curr_data;
var displaytype_tmp =  "{b} : {d}%";
var total = 0;
var xuzhoushi = "320300";

//xuzhoushi 应该是用户本身所在区的sectionid

var lbl1 = null,lbl2 = null,lbl3 = null,lbl4 = null;
var thecity = null;
function housetypeFrame(){
	sendToBfmis_remote(REQUEST_TYPE1017, {view: "VB",belongsectionid:xuzhoushi, belongsectionlevel:2}, function(data){
		for (var i = 0; i < data.length; i++) {
			if(data[i].id == xuzhoushi){
				thecity = data[i];
				$("#lblhouse1").html("区域：" + data[i].text);
				$("#county").combobox("loadData",data[i].children);
				break;
			}
		}
	});
	$("#county").combobox({
		onChange: function (n,o) {
			getcombobox(n,"village");
		},onSelect: function(param){
			lbl1 = param;
			lbl2 = lbl3 = lbl4 = null;
			$("#village").combobox("loadData",[]);
			$("#building").combobox("loadData",[]);
			$("#cell").combobox("loadData",[]);
			$("#lblhouse2").html(lbl1.text);
		}
	});
	$("#village").combobox({
		onChange: function (n,o) {
			getcombobox(n,"building");
		},onSelect: function(param){
			lbl2 = param;
			lbl3 = lbl4 = null;
			$("#building").combobox("loadData",[]);
			$("#cell").combobox("loadData",[]);
			$("#lblhouse2").html(lbl1.text + "-" + lbl2.text);
		}
	});
	$("#building").combobox({
		onChange: function (n,o) {
			getcombobox(n,"cell");
		},onSelect: function(param){
			lbl3 = param;
			lbl4 = null;
			$("#cell").combobox("loadData",[]);
			$("#lblhouse2").html(lbl1.text + "-" + lbl2.text + "-" + lbl3.text);
		}
	});
	$("#cell").combobox({
		onChange: function (n,o) {
		},onSelect: function(param){
			lbl4 = param;
			$("#lblhouse2").html(lbl1.text + "-" + lbl2.text + "-" + lbl3.text + "-" + lbl4.text);
		}
	});
}
function getcombobox(newvalue,id){
	sendToBfmis_remote(REQUEST_TYPE1017, {view: "VB",parent_id : newvalue,belongsectionid:xuzhoushi, belongsectionlevel:2},function(childrenData){
		for (var i = 0; i < childrenData.length; i++) {
			if(!childrenData[i].text){
				childrenData[i].text = "未定义";
			} 
		}
		$("#" + id).combobox("loadData",childrenData);
	});
}
function startcount_ht(){
	if(lbl4 != null){
		selectedHandler1(lbl4);
	} else if(lbl3 != null){
		selectedHandler1(lbl3);
	} else if(lbl2 != null){
		selectedHandler1(lbl2);
	} else if(lbl1 != null){
		selectedHandler1(lbl1);
	}  else {
		selectedHandler1(thecity);
	}
}

function selectedHandler1(parm) {
	curr_parm = parm;
	var housetype_params = {};
	housetype_params[housetype_ht_flag] = 1;
	housetype_params[groupcontent_flag] = 1;
	switch (parm.type) {
	case 'S':
		housetype_params.sectionid = parm.id;
		break;
	case 'V':
		housetype_params.villageid = parm.id;
		break;
	case 'B':
		housetype_params.buildingid = parm.id;
		break;
	case 'BC':
		housetype_params.buildingid = parm.parent_id;
		housetype_params.cellid = parm.id;
		break;
	default:
		break;
	}
	setTimeout(function() { // 延迟加载 先完成树的加载 为了不让 查询的mask被树加载的unmask去除
		MaskUtil.mask();
		sendToBfmis_remote(REQUEST_TYPE152, housetype_params, function(data){
			curr_data = data;
			if(data != null){
				housetype_chart(data);
			}
		});
	}, 200);
}

function displaytype(v){
	displaytype_ht_flag = v;
	if(curr_data != null){
		housetype_chart(curr_data);
	}
}

function housetype_chart(data){
	MaskUtil.mask();
	var series_tmp = [],legend_data = [] ,yname = '',series_data = {},tmp = [];
	var countnum = {};
	total = 0;
	for (var i = 0; i < data.length; i++) {
		if(data[i][housetype_ht_flag + '_chs'] != null){
			series_data = {};
			if(amount_flag == 1){
				series_data.value = data[i][groupcontent_flag];
				yname = '(单位：元)';
			} else if(amount_flag == 2){
				series_data.value = (data[i][groupcontent_flag] / 10000).toFixed(2);
				yname = '(单位：万元)';
			} else if(amount_flag == 3){
				series_data.value = (data[i][groupcontent_flag] / 100000000).toFixed(2);
				yname = '(单位：亿元)';
			}
			if( tmp.indexOf(data[i][housetype_ht_flag+ '_chs']) == -1){
				tmp.push(data[i][housetype_ht_flag + '_chs']);
				countnum[data[i][housetype_ht_flag + '_chs']] = 0 + series_data.value
			} else {
				countnum[data[i][housetype_ht_flag + '_chs']] += series_data.value;
			}
			
			
//			series_data.name = data[i][housetype_ht_flag + '_chs'] + ' ' + series_data.value;
//			series_tmp.push(series_data);
//			legend_data.push(series_data.name);
			total += parseFloat(series_data.value);
		}
	}
	total = total.toFixed(2);
	var datas = {};
	for (var i = 0; i < tmp.length; i++) {
		var tt = tmp[i];
		var tt1 = countnum[tt];
			tt1 = Math.round(tt1 * 100) / 100; 
		var series_data1 = {};
		series_data1.name = tt + " " + tt1;
		series_data1.value = tt1;
		series_tmp.push(series_data1);
		legend_data.push(series_data1.name);
	}
	switch (displaytype_ht_flag) {
	//{a}（系列名称），{b}（数据项名称），{c}（数值）, {d}（百分比）
	case '1':
		displaytype_tmp =  "{b} : {d}%";
		break;
	case '2':
		displaytype_tmp =  "{b} : {d}% of " + total;
		break;
	default:
		break;
	}
	datas.series_tmp = series_tmp;
	datas.legend_data = legend_data;
	datas.yname = yname;
	datas.textname = '房屋性质分析';
	datas.displaytype_tmp = displaytype_tmp;
	var a = data;
	pie_datas(datas);
}

function pie_datas(datas){
	myChart = echarts.init(document.getElementById('main'));
	var option = {
			title : {
				text : datas.textname,
				subtext : datas.yname,
				x : 'center'
			},
			tooltip : {
				trigger : 'item',
				formatter : datas.displaytype_tmp
			},
			legend : {
				orient : 'vertical',
				left : 'left',
				data : datas.legend_data
			},
			series : [ {
				type : 'pie',
				radius : '55%',
				center : [ '50%', '60%' ],
				data : datas.series_tmp,
				itemStyle : {
					emphasis : {
						shadowBlur : 10,
						shadowOffsetX : 0,
						shadowColor : 'rgba(0, 0, 0, 0.5)'
					}
				}
			} ]
	};
	myChart.setOption(option);
	MaskUtil.unmask();
}

/**
 * 资金余额银行分布分析
 */
var housetype_bb_flag = 'all';
var curr_param_pub = null;
var curr_date_flag_bb = '1';
function bankbalanceFrame(){
	document.onkeydown = (function(event){
		if(event.keyCode == 13){ 
			startcount_bankbalance();
		}
	});
	curr_param_pub = null;
	pubgroup_conditions = 's_balance';
	amount_flag = 1;
	$("input[name='groupbalance_bb']").change(function(){
		if(curr_param_pub != null){
			curr_param_pub.yname = '                  资金余额银行分布分析';
			pubgroup_conditions = groupbalance_bb_flag;
			datas_load(curr_param_pub);
		}
	});
	$("input[name='accounttype_bb']").change(function(){
		startcount_bankbalance();
	});
	$("input[name='date_bb']").change(function(){
		if(curr_date_flag_bb == '2'){
			document.getElementById("datebox_bb").style.visibility="visible";
		} else {
			document.getElementById("datebox_bb").style.visibility="hidden";
		}
	});
	var yname = '                  资金余额银行分布分析';
	noneContent_bar(yname);
}

function startcount_bankbalance(){
	var param = {};
	if(housetype_bb_flag != 'all'){
		param.housetype_bb_flag = housetype_bb_flag;
	}
	if(curr_date_flag_bb != '1'){
		param.updated = $("#datebox1_bb").datebox('getValue');
	} else {
		param.updated = date_now;
	}
	if(param.updated == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		sendToBfmis_remote(REQUEST_TYPE153, param, function(data){
			data.yname = '                  资金余额银行分布分析';
			data.chs = 'bankid_chs';
			data.series_name = '银行';
			curr_param_pub = data;
			datas_load(data);
		});
	}
}

function datas_load(data){
//	data.yname = '                   资金余额银行分布分析';
	var tmpname = data.yname;
	var groupbalance_sum = [],xdates = [];
	var total = 0;
	for (var i = 0; i < data.length; i++) {
		xdates.push(data[i][data.chs]);
		if(amount_flag == 1){
			groupbalance_sum.push(data[i][pubgroup_conditions]);
		} else if(amount_flag == 2){
			groupbalance_sum.push((data[i][pubgroup_conditions] / 10000).toFixed(2));
		} else if(amount_flag == 3){
			groupbalance_sum.push((data[i][pubgroup_conditions] / 100000000).toFixed(2));
		}
		total += parseFloat(data[i][pubgroup_conditions]);
//		total += parseFloat(groupbalance_sum[i]);
	}
	data.xdates = xdates;
	data.groupbalance_sum = groupbalance_sum;
	if(amount_flag == 1){
		data.yname += '(单位：元)';
		y_name = '(单位：元)';
	} else if(amount_flag == 2){
		data.yname = '        ' + data.yname + '(单位：万元)';
		y_name = '(单位：万元)';
		total = (total / 10000).toFixed(2);
	} else if(amount_flag == 3){
		data.yname = '                   ' + data.yname +  '(单位：亿元)';
		y_name = '(单位：亿元)';
		total = (total / 100000000).toFixed(2);
	}
	var datas = {};
	var series_tmp = [];
	var legend_data = [];
	for (var i = 0; i < xdates.length; i++) {
		var tt = xdates[i];
		var tt1 = groupbalance_sum[i];
			tt1 = Math.round(tt1 * 100) / 100; 
		var series_data1 = {};
		series_data1.name = tt + " " + tt1;
		series_data1.value = tt1;
		series_tmp.push(series_data1);
		legend_data.push(series_data1.name);
	}
	datas.series_tmp = series_tmp;
	datas.legend_data = legend_data;
	datas.yname = y_name;
	datas.textname = tmpname;
//	total = parseFloat(total.toFixed(2));
//	var tmpm = changetomoney(total);
	datas.displaytype_tmp = "{b} : {d}%" + " of " +  total;
	if(type_checked == "bar"){
		draw_histogram(data);
	} else {
		datas.textname = datas.textname.substring(18, datas.textname.length);
		pie_datas(datas);
	}
}

function draw_histogram(data){
	myChart = echarts.init(document.getElementById('main'));
	var option = {
			// {a}（系列名称），{b}（类目值），{c}（数值）, {d}（无）
			tooltip : {
				trigger : 'item',
				formatter: data.tooltip_formatter
			},
			calculable : true,
			legend : {
				data : [ 'Growth', data.series_name],
				itemGap : 5
			},
			grid : {
				top : '12%',
				left : '1%',
				right : '10%',
				containLabel : true
			},
			xAxis : [ {
				type : 'category',
				data : data.xdates
			} ],
			yAxis : [ {
				type : 'value',
				name : data.yname,
				axisLabel : {
					formatter : function(a) {
						a = +a;
						return isFinite(a) ? echarts.format.addCommas(+a )
								: '';
					}
				}
			} ],
			dataZoom : [ {
				show : true,
				start : 1,
				end : 100
			}, {
				type : 'inside',
				start : 94,
				end : 100
			}, {
				show : true,
				yAxisIndex : 0,
				filterMode : 'empty',
				width : 30,
				height : '80%',
				showDataShadow : false,
				left : '93%'
			} ],
			series : [ {
				name : data.series_name,
				type : 'bar',
				label: {
	                normal: {
	                    show: true,
	                    position: 'top'
	                }
	            },
				data : data.groupbalance_sum
			} ]
		};
	myChart.setOption(option);
}

/**
 *  柜员缴存流量分布分析
 */
function captureflowFrame(){
	document.onkeydown = (function(event){
		if(event.keyCode == 13){ 
			startcount_cf();
		}
	});
	curr_param_pub = null;
	pubgroup_conditions = 's_billcount';
	$("#datebox1_cf").datebox('setValue',date_last);
	$("#datebox2_cf").datebox('setValue',date);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1080)'}, function(data){
		$("#paystatus_cf").combobox('loadData',data);
	});
	$("input[name='acount_cf']").change(function(){
		if(curr_param_pub != null){
			curr_param_pub.yname = '                  柜员缴存流量分布分析';
			datas_load(curr_param_pub);
		}
	});
	var yname = '                  柜员缴存流量分布分析';
	noneContent_bar(yname);
}
function startcount_cf(){
	var datas = {};
	var datebox1_cf = $("#datebox1_cf").datebox('getValue');
	var datebox2_cf = $("#datebox2_cf").datebox('getValue');
	if(datebox1_cf == "" || datebox2_cf == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		var symbol = $("#symbol_cf").combobox('getValue');
		var paystatus = $("#paystatus_cf").combobox('getValue');
		if(symbol != "all" && symbol !== ""){
			datas.symbol = symbol;
		}
		if(paystatus != ""){
			datas.paystatus = paystatus;
		}
		datas.datebox1_cf = datebox1_cf;
		datas.datebox2_cf = datebox2_cf;
		sendToBfmis_remote(REQUEST_TYPE154, datas, function(data){
			data.yname = '                  柜员缴存流量分布分析';
			data.chs = 'createdby_chs';
			data.series_name = '缴存流量';
			data.tooltip_formatter = '{b}: \n{c}';
			curr_param_pub = data;
			datas_load(data);
		});
	}
}

/**
 * 时点缴存流量分布分析
 */
function timeflowFrame(){
	document.onkeydown = (function(event){
		if(event.keyCode == 13){ 
			startcount_tf();
		}
	});
	curr_param_pub = null;
	pubgroup_conditions = 's_billcount';
	$("#datebox1_tf").datebox('setValue',date_now);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1080)'}, function(data){
		$("#paystatus_tf").combobox('loadData',data);
	});
	var yname = '                  时点缴存流量分布分析';
	noneContent_bar(yname);
	$("input[name='acount_tf']").change(function(){
		if(curr_param_pub != null){
			curr_param_pub.yname = '                  时点缴存流量分布分析';
			datas_load(curr_param_pub);
		}
	});
}

function startcount_tf(){
	var datas = {};
	var times = $("#datebox1_tf").datebox('getValue');
	if(times == null || times == ""){
		$.messager.alert('错误','日期不能为空！','error');
	} else {
		var datebox1_tf = times + ' 00:00:00';
		var datebox2_tf = times + ' 23:59:59';
		var symbol = $("#symbol_tf").combobox('getValue');
		var paystatus = $("#paystatus_tf").combobox('getValue');
		if(symbol != "all" && symbol !== ""){
			datas.symbol = symbol;
		}
		if(paystatus != ""){
			datas.paystatus = paystatus;
		}
		datas.datebox1_tf = datebox1_tf;
		datas.datebox2_tf = datebox2_tf;
		datas.created = 1;
		sendToBfmis_remote(REQUEST_TYPE155, datas, function(data){
			var tmp = [];
			for (var i = 0 ; i < 24; i++) {
				var tmpflag = 1;
				for (var j = 0; j < data.length; j++) {
					if(parseInt(data[j].created) == i){
						tmp.push(data[j]);
						tmpflag = 0;
						break;
					} else {
						tmpflag = 1;
					}
				}
				if(tmpflag == 1)
					tmp.push({created : i,s_billcount:0,s_housecount:0,s_paymentamount:0});
			}
			tmp.yname = '                  时点缴存流量分布分析';
			tmp.chs = 'created';
			tmp.series_name = '时点缴存流量';
			tmp.tooltip_formatter = '{b}时: \n{c}';
			curr_param_pub = tmp;
			datas_load(tmp);
		});
	}
}

/**
 * 资金性质流量分布分析
 */
function fundtypeflowFrame(){
	curr_param_pub = null;
	pubgroup_conditions = 's_billcount';
	$("#datebox1_ftf").datebox('setValue',date_last);
	$("#datebox2_ftf").datebox('setValue',date);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1080)'}, function(data){
		$("#paystatus_ftf").combobox('loadData',data);
	});
	$("input[name='acount_ftf']").change(function(){
		if(curr_param_pub != null){
			curr_param_pub.yname = '                  资金性质流量分布分析';
			datas_load(curr_param_pub);
		}
	});
	var yname = '                  资金性质流量分布分析';
	noneContent_bar(yname);
}

function startcount_ftf(){
	var datas = {};
	var datebox1_ftf = $("#datebox1_ftf").datebox('getValue');
	var datebox2_ftf = $("#datebox2_ftf").datebox('getValue');
	if(datebox1_ftf == "" || datebox2_ftf == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		var symbol = $("#symbol_ftf").combobox('getValue');
		var paystatus = $("#paystatus_ftf").combobox('getValue');
		if(symbol != "all" && symbol !== ""){
			datas.symbol = symbol;
		}
		if(paystatus != ""){
			datas.paystatus = paystatus;
		}
		datas.datebox1_ftf = datebox1_ftf;
		datas.datebox2_ftf = datebox2_ftf;
		datas.fundtype = 1;
		sendToBfmis_remote(REQUEST_TYPE155, datas, function(data){
			data.yname = '                  资金性质流量分布分析';
			data.chs = 'fundtype_chs'; 
			data.series_name = '资金性质流量';
			data.tooltip_formatter = '{b}: \n{c}';
			curr_param_pub = data;
			datas_load(data);
		});
	}
}

/**
 * 收款银行流量分布分析
 */
function bankidflowFrame(){
	curr_param_pub = null;
	pubgroup_conditions = 's_billcount';
	$("#datebox1_bif").datebox('setValue',date_last);
	$("#datebox2_bif").datebox('setValue',date);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1080)'}, function(data){
		$("#paystatus_bif").combobox('loadData',data);
	});
	$("input[name='acount_bif']").change(function(){
		if(curr_param_pub != null){
			curr_param_pub.yname = '                  收款银行流量分布分析';
			datas_load(curr_param_pub);
		}
	});
	var yname = '                  收款银行流量分布分析';
	noneContent_bar(yname);
}
function startcount_bif(){
	var datas = {};
	var datebox1_bif = $("#datebox1_bif").datebox('getValue');
	var datebox2_bif = $("#datebox2_bif").datebox('getValue');
	if(datebox1_bif == "" || datebox2_bif == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		var symbol = $("#symbol_bif").combobox('getValue');
		var paystatus = $("#paystatus_bif").combobox('getValue');
		if(symbol != "all" && symbol !== ""){
			datas.symbol = symbol;
		}
		if(paystatus != ""){
			datas.paystatus = paystatus;
		}
		datas.datebox1_bif = datebox1_bif;
		datas.datebox2_bif = datebox2_bif;
		datas.bankid = 1;
		sendToBfmis_remote(REQUEST_TYPE155, datas, function(data){
			data.yname = '                  收款银行流量分布分析';
			data.chs = 'bankid_chs';
			data.series_name = '收款银行流量';
			data.tooltip_formatter = '{b}: \n{c}';
			curr_param_pub = data;
			datas_load(data);
		});
	}
}

/**
 * 资金使用划拨情况
 */
var dateflag_fug = null;
function fundusegiveFrame(){
	dateflag_fug = '1';
	pubgroup_conditions = 's_giveamount';
	$("#datebox1_fug").datebox('setValue',date_last);
	$("#datebox2_fug").datebox('setValue',date);
	sendToBfmis_remote(REQUEST_TYPE1016, {constantcategoryids:'(1972)'}, function(data){
		$("#paystatus_fug").combobox('loadData',data);
	});
	var yname = '                  资金使用划拨情况分析';
	noneContent_bar(yname);
}

function startcount_fug(){
	var datas = {};
	var datebox1_fug = $("#datebox1_fug").datebox('getValue');
	var datebox2_fug = $("#datebox2_fug").datebox('getValue');
	var fundtype = $("#paystatus_fug").combobox("getValue");
	if(datebox1_fug == "" || datebox2_fug == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		if(fundtype != ""){
			datas.fundtype = fundtype;
		}
		datas.datebox1_fug = datebox1_fug;
		datas.datebox2_fug = datebox2_fug;
		datas.dateflag_fug = dateflag_fug;
		sendToBfmis_remote(REQUEST_TYPE156, datas, function(data){
			data.yname = '                  资金使用划拨情况分析';
			data.chs = 'enterdate';
			data.series_name = '资金使用情况';
			data.tooltip_formatter = '{b}: \n{c}';
			curr_param_pub = data;
			datas_load(data);
		});
	}
}
/**
 * 专户增值收益统计分析
 */
var dateflag_fav = null;
function fundaddvalueFrame(){
	amount_flag = 1;
	dateflag_fav = '1';
	curr_param_pub = null;
	pubgroup_conditions = '';
	$("#datebox1_fav").datebox('setValue',date_last);
	$("#datebox2_fav").datebox('setValue',date);
	var yname = '                  专户增值收益统计分析';
	noneContent_bar(yname); 
}
function startcount_fav(){
	var datas = {};
	var datebox1_fav = $("#datebox1_fav").datebox('getValue');
	var datebox2_fav = $("#datebox2_fav").datebox('getValue');
	if(datebox1_fav == "" || datebox2_fav == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		datas.dateflag_fav = dateflag_fav;
		datas.datebox1_fav = datebox1_fav;
		datas.datebox2_fav = datebox2_fav;
		sendToBfmis_remote(REQUEST_TYPE157, datas, function(data){
			curr_param_pub = data;
			load_data2(data);
		});
	}
}
function fundadd_fun(){
	if(curr_param_pub != null){
		load_data2(curr_param_pub);
	}
}
function load_data2(data){
	var dtmp = {},xdates = [];
	var lxye = [],dqlx = [],hqlx = [],yqlx = [],zhlxsum = [],wtlx = [],yzlx = [],yzlxsum = [];
	var yname = '                  专户增值收益统计分析';
	for (var i = 0; i < data.length; i++) {
		xdates.push(data[i].enterdate);
		if(amount_flag == 1){
			lxye.push(data[i].lxye);
			dqlx.push(data[i].dqlx);
			hqlx.push(data[i].hqlx);
			yqlx.push(data[i].yqlx);
			zhlxsum.push(data[i].zhlxsum);
			wtlx.push(data[i].wtlx);
			yzlx.push(data[i].yzlx);
			yzlxsum.push(data[i].yzlxsum);
		} else if(amount_flag == 2){
			lxye.push((data[i].lxye / 10000).toFixed(2));
			dqlx.push((data[i].dqlx / 10000).toFixed(2));
			hqlx.push((data[i].hqlx / 10000).toFixed(2));
			yqlx.push((data[i].yqlx / 10000).toFixed(2));
			zhlxsum.push((data[i].zhlxsum / 10000).toFixed(2));
			wtlx.push((data[i].wtlx / 10000).toFixed(2));
			yzlx.push((data[i].yzlx / 10000).toFixed(2));
			yzlxsum.push((data[i].yzlxsum / 10000).toFixed(2));
		} else if(amount_flag == 3){
			lxye.push((data[i].lxye / 100000000).toFixed(2));
			dqlx.push((data[i].dqlx / 100000000).toFixed(2));
			hqlx.push((data[i].hqlx / 100000000).toFixed(2));
			yqlx.push((data[i].yqlx / 100000000).toFixed(2));
			zhlxsum.push((data[i].zhlxsum / 100000000).toFixed(2));
			wtlx.push((data[i].wtlx / 100000000).toFixed(2));
			yzlx.push((data[i].yzlx / 100000000).toFixed(2));
			yzlxsum.push((data[i].yzlxsum / 100000000).toFixed(2));
		}
	}
	if(amount_flag == 1){
		yname += '(单位：元)';
	} else if(amount_flag == 2){
		yname += '(单位：万元)';
	} else if(amount_flag == 3){
		yname += '(单位：亿元)';
	}
	dtmp.dqlx = dqlx;
	dtmp.hqlx = hqlx;
	dtmp.yqlx = yqlx;
	dtmp.zhlxsum = zhlxsum;
	dtmp.wtlx = wtlx;
	dtmp.yzlx = yzlx;
	dtmp.yzlxsum = yzlxsum;
	
	myChart = echarts.init(document.getElementById('main'));
	// 指定图表的配置项和数据
	var option = {
		tooltip : {
			trigger : 'item'
		},
		calculable : true,
		legend : {
			data : [ 'Growth', '息差'],
			itemGap : 5
		},
		grid : {
			top : '12%',
			left : '1%',
			right : '10%',
			containLabel : true
		},
		xAxis : [ {
			type : 'category',
			data : xdates
		} ],
		yAxis : [ {
			type : 'value',
			name : yname,
			axisLabel : {
				formatter : function(a) {
					a = +a;
					return isFinite(a) ? echarts.format.addCommas(+a )
							: '';
				}
			}
		} ],
		dataZoom : [ {
			show : true,
			start : 54,
			end : 100
		}, {
			type : 'inside',
			start : 94,
			end : 100
		}, {
			show : true,
			yAxisIndex : 0,
			filterMode : 'empty',
			width : 30,
			height : '80%',
			showDataShadow : false,
			left : '93%'
		} ],
		series : [ {
			name : '息差',
			type : 'bar',
			label: {
                normal: {
                    show: true,
                    position: 'top'
                }
            },
			data : lxye
		} ]
	};
	for (var i = 0; i < fundadd_checkbox.length; i++) {
		if(fundadd_checkbox[i].checked){
			var tmp = {};
			tmp.name = fundadd_checkbox[i].title;
			tmp.type = 'bar';
			tmp.label = {normal:{ show: true,  position: 'top' }};
			tmp.data = dtmp[fundadd_checkbox[i].value];
			option.series.push(tmp);
			option.legend.data.push(tmp.name);
		}
	}
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}
/**
 * 业主账户变化统计分析
 * TODO 业主账户变化统计分析
 */
function dayendstatdetailFrame(){
	amount_flag = 1;
	dateflag_desd = '1';
	curr_param_pub = null;
	pubgroup_conditions = '';
	$("#datebox1_desd").datebox('setValue',date_last);
	$("#datebox2_desd").datebox('setValue',date);
	var yname = '                  业主账户变化统计分析';
	noneContent_bar(yname);
}
function startcount_desd(){
	var datas = {};
	var datebox1_desd = $("#datebox1_desd").datebox('getValue');
	var datebox2_desd = $("#datebox2_desd").datebox('getValue');
	if(datebox1_desd == "" || datebox2_desd == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		datas.dateflag_desd = dateflag_desd;
		datas.datebox1_desd = datebox1_desd;
		datas.datebox2_desd = datebox2_desd;
		sendToBfmis_remote(REQUEST_TYPE158, datas, function(data){
			curr_param_pub = data;
			load_data3(data);
		});
	}
}
function load_data3(data){
	var dtmp = {},xdates = [];
	var currbalance = [],addinterest = [],payamount = [],interest = [],useamount = [],repealamount = [];
	var yname = '                  业主账户变化统计分析';
	for (var i = 0; i < data.length; i++) {
		xdates.push(data[i].workdate);
		if(amount_flag == 1){
			currbalance.push(data[i].currbalance);
			addinterest.push(data[i].addinterest);
			payamount.push(data[i].payamount);
			interest.push(data[i].interest);
			useamount.push(data[i].useamount);
			repealamount.push(data[i].repealamount);
		} else if(amount_flag == 2){
			currbalance.push((data[i].currbalance / 10000).toFixed(2));
			addinterest.push((data[i].addinterest / 10000).toFixed(2));
			payamount.push((data[i].payamount / 10000).toFixed(2));
			interest.push((data[i].interest / 10000).toFixed(2));
			useamount.push((data[i].useamount / 10000).toFixed(2));
			repealamount.push((data[i].repealamount / 10000).toFixed(2));
		} else if(amount_flag == 3){
			currbalance.push((data[i].currbalance / 100000000).toFixed(2));
			addinterest.push((data[i].addinterest / 100000000).toFixed(2));
			payamount.push((data[i].payamount / 100000000).toFixed(2));
			interest.push((data[i].interest / 100000000).toFixed(2));
			useamount.push((data[i].useamount / 100000000).toFixed(2));
			repealamount.push((data[i].repealamount / 100000000).toFixed(2));
		}
	}
	if(amount_flag == 1){
		yname += '(单位：元)';
	} else if(amount_flag == 2){
		yname += '(单位：万元)';
	} else if(amount_flag == 3){
		yname += '(单位：亿元)';
	}
	dtmp.currbalance = currbalance;
	dtmp.addinterest = addinterest;
	dtmp.payamount = payamount;
	dtmp.interest = interest;
	dtmp.useamount = useamount;
	dtmp.repealamount = repealamount;
	
	myChart = echarts.init(document.getElementById('main'));
	// 指定图表的配置项和数据
	var option = {
		tooltip : {
			trigger : 'item'
		},
		calculable : true,
		legend : {
			data : [ 'Growth'],
			itemGap : 5
		},
		grid : {
			top : '12%',
			left : '1%',
			right : '10%',
			containLabel : true
		},
		xAxis : [ {
			type : 'category',
			data : xdates
		} ],
		yAxis : [ {
			type : 'value',
			name : yname,
			axisLabel : {
				formatter : function(a) {
					a = +a;
					return isFinite(a) ? echarts.format.addCommas(+a )
							: '';
				}
			}
		} ],
		dataZoom : [ {
			show : true,
			start : 54,
			end : 100
		}, {
			type : 'inside',
			start : 94,
			end : 100
		}, {
			show : true,
			yAxisIndex : 0,
			filterMode : 'empty',
			width : 30,
			height : '80%',
			showDataShadow : false,
			left : '93%'
		} ],
		series : [ ]
	};
	for (var i = 0; i < dayendstatdetail_checkbox.length; i++) {
		if(dayendstatdetail_checkbox[i].checked){
			var tmp = {};
			tmp.name = dayendstatdetail_checkbox[i].title;
			tmp.type = 'bar';
			tmp.label = {normal:{ show: true,  position: 'top' }};
			tmp.data = dtmp[dayendstatdetail_checkbox[i].value];
			option.series.push(tmp);
			option.legend.data.push(tmp.name);
		}
	}
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}
/**
 * 资金使用项目分析
 * 
 */
var acount1_fup = 'billcount',acount_fup = 'mainitem';
function funduseprojectFrame(){
	displaytype_ht_flag = '1';
	acount1_fup = 'billcount',acount_fup = 'mainitem'
	curr_param_pub = null;
	amount_flag = 1;
	pubgroup_conditions = '';
	$("#datebox1_fup").datebox('setValue',date_last);
	$("#datebox2_fup").datebox('setValue',date);
}
function acountfup(value){
	acount1_fup = value;
	if(curr_param_pub != null){
		loadpie_data(curr_param_pub);
	}
}
function startcount_fup(){
	var datas = {};
	datas.datebox1_fup = $("#datebox1_fup").datebox('getValue');
	datas.datebox2_fup = $("#datebox2_fup").datebox('getValue');
	if(datas.datebox1_fup == "" || datas.datebox2_fup == ""){
		$.messager.alert("错误","日期不能为空！","error");
	} else {
		datas[acount_fup] = 1;
		sendToBfmis_remote(REQUEST_TYPE159, datas, function(data){
			curr_param_pub = data;
			if(curr_param_pub != null){
				loadpie_data(curr_param_pub);
			}
		});
	}
}
function loadpie_data(data){
	var series_tmp = [],legend_data = [] ,yname = '',series_data = {};
	total = 0;
	displaytype_tmp =  "{b} : {d}%";
	for (var i = 0; i < data.length; i++) {
		if(data[i][acount1_fup] != null){
			series_data = {};
			if(amount_flag == 1){
				series_data.value = data[i][acount1_fup];
				yname = '(单位：元)';
			} else if(amount_flag == 2){
				series_data.value = (data[i][acount1_fup] / 10000).toFixed(2);
				yname = '(单位：万元)';
			} else if(amount_flag == 3){
				series_data.value = (data[i][acount1_fup] / 100000000).toFixed(2);
				yname = '(单位：亿元)';
			}
			series_data.name = data[i]['keyname'] + ' ' + series_data.value;
			series_tmp.push(series_data);
			legend_data.push(series_data.name);
			total += parseFloat(series_data.value);
		}
	}
	total = total.toFixed(2);
	switch (displaytype_ht_flag) {
	//{a}（系列名称），{b}（数据项名称），{c}（数值）, {d}（百分比）
	case '1':
		displaytype_tmp =  "{b} : {d}%";
		break;
	case '2':
		displaytype_tmp =  "{b} : {d}% of " + total;
		break;
	default:
		break;
	}
	myChart = echarts.init(document.getElementById('main'));
	var option = {
			title : {
				text : '资金使用项目分析',
				subtext : yname,
				x : 'center'
			},
			tooltip : {
				trigger : 'item',
				formatter : displaytype_tmp
			},
			legend : {
				orient : 'vertical',
				left : 'left',
				data : legend_data
			},
			series : [ {
				type : 'pie',
				radius : '55%',
				center : [ '50%', '60%' ],
				data : series_tmp,
				itemStyle : {
					emphasis : {
						shadowBlur : 10,
						shadowOffsetX : 0,
						shadowColor : 'rgba(0, 0, 0, 0.5)'
					}
				}
			} ]
	};
	myChart.setOption(option);
}
function displaytype_fup(v){
	displaytype_ht_flag = v;
	if(curr_param_pub != null){
		loadpie_data(curr_param_pub);
	}
}

/**
 * 
 */
function noneContent_bar(yname){
	myChart = echarts.init(document.getElementById('main'));
	// 指定图表的配置项和数据
	var option = {
		tooltip : {
			trigger : 'item'
		},
		calculable : true,
		legend : {
			data : [ 'Growth','11'],
			itemGap : 5,
			height: '100%',
			width : '100%'
		},
		grid : {
			top : '12%',
			left : '1%',
			right : '10%',
			containLabel : true
		},
		xAxis : [ {
			type : 'category',
			data : []
		} ],
		yAxis : [ {
			type : 'value',
			name : yname,
			axisLabel : {
				formatter : function(a) {
					a = +a;
					return isFinite(a) ? echarts.format.addCommas(+a )
							: '';
				}
			}
		} ],
		dataZoom : [ {
			show : true,
			start : 54,
			end : 100
		}, {
			type : 'inside',
			start : 94,
			end : 100
		}, {
			show : true,
			yAxisIndex : 0,
			filterMode : 'empty',
			width : 30,
			height : '80%',
			showDataShadow : false,
			left : '93%'
		} ],
		series : [ {
			name : '2',
			type : 'bar',
			label: {
                normal: {
                    show: true,
                    position: 'top'
                }
            },
			data : []
		} ]
	};
	// 使用刚指定的配置项和数据显示图表。
	myChart.setOption(option);
}

function changetomoney(str){//Rekey 
	try {
		str = str.toString();
		var tmp = str.split('.');
		var len = tmp[0].length, str2 = '', max = Math.floor(len / 3); 
		for(var i = 0 ; i < max ; i++){ 
			var s = tmp[0].slice(len - 3, len); 
			tmp[0] = tmp[0].substr(0, len - 3); 
			str2 = (',' + s) + str2; 
			len = tmp[0].length; 
		} 
		tmp[0] += str2; 
		if(!tmp[1]){
			tmp[1] = "";
		} else {
			tmp[1] = "." + tmp[1];
		}
		if(tmp[0].substring(0,1) == ","){
			return tmp[0].substring(1, tmp[0].length) + tmp[1];
		} else {
			return tmp[0] + tmp[1];
		}
	} catch (e) {
		// TODO: handle exception
	}
} 

//微信 侧滑菜单 专用
var width = $(window).width();
var swipe,swipe1;
function screening(){
	swipe = Swipe();
	var div = document.getElementById('screenContent'); 
	$("#screenContent").css("display","");
	$("#mark_div").css("display","");
	swipe.scrollTo(300);  
}
function Swipe() {
	var div = document.getElementById('screenContent'); 
	var swipe = {};
	var $element = $("#screenContent:hidden");  
	//显示动画  
	swipe.scrollTo = function(speed) {
		$element.show();
		$element.animate({
			left : '-=' + width*0.8
		}, speed, function() {
		});

		return this;
	};
	swipe.hiddenTo = function(speed) {
		$element.animate({
			left : '+=' + width*0.8
		}, speed, function() {
			$element.hide(); 
			swipe = undefined;
		});
	};

	return swipe;  
}
function closewin(){
	swipe.hiddenTo(300);
	$("#mark_div").css("display","none");
}


